package o;

import android.annotation.TargetApi;
import android.media.AudioTimestamp;
import android.media.AudioTrack;
import androidx.annotation.Nullable;

final class acg {
    private long ʻ;
    private long ˊ;
    private long ˋ;
    private int ˎ;
    private long ˏ;
    @Nullable
    private final c ॱ;

    @TargetApi(19)
    static final class c {
        private final AudioTimestamp ˊ = new AudioTimestamp();
        private long ˋ;
        private long ˎ;
        private long ˏ;
        private final AudioTrack ॱ;

        public c(AudioTrack audioTrack) {
            this.ॱ = audioTrack;
        }

        public boolean ˊ() {
            boolean timestamp = this.ॱ.getTimestamp(this.ˊ);
            if (timestamp) {
                long j = this.ˊ.framePosition;
                if (this.ˎ > j) {
                    this.ˏ++;
                }
                this.ˎ = j;
                this.ˋ = j + (this.ˏ << 32);
            }
            return timestamp;
        }

        public long ˋ() {
            return this.ˊ.nanoTime / 1000;
        }

        public long ॱ() {
            return this.ˋ;
        }
    }

    public acg(AudioTrack audioTrack) {
        if (anr.ˋ >= 19) {
            this.ॱ = new c(audioTrack);
            ˋ();
            return;
        }
        this.ॱ = null;
        ॱ(3);
    }

    public boolean ˋ(long j) {
        if (this.ॱ == null || j - this.ˏ < this.ˊ) {
            return false;
        }
        this.ˏ = j;
        boolean ˊ = this.ॱ.ˊ();
        switch (this.ˎ) {
            case 0:
                if (ˊ) {
                    if (this.ॱ.ˋ() < this.ˋ) {
                        return false;
                    }
                    this.ʻ = this.ॱ.ॱ();
                    ॱ(1);
                    return ˊ;
                } else if (j - this.ˋ <= 500000) {
                    return ˊ;
                } else {
                    ॱ(3);
                    return ˊ;
                }
            case 1:
                if (!ˊ) {
                    ˋ();
                    return ˊ;
                } else if (this.ॱ.ॱ() <= this.ʻ) {
                    return ˊ;
                } else {
                    ॱ(2);
                    return ˊ;
                }
            case 2:
                if (ˊ) {
                    return ˊ;
                }
                ˋ();
                return ˊ;
            case 3:
                if (!ˊ) {
                    return ˊ;
                }
                ˋ();
                return ˊ;
            case 4:
                return ˊ;
            default:
                throw new IllegalStateException();
        }
    }

    public void ˊ() {
        ॱ(4);
    }

    public void ˎ() {
        if (this.ˎ == 4) {
            ˋ();
        }
    }

    public boolean ˏ() {
        return this.ˎ == 1 || this.ˎ == 2;
    }

    public boolean ॱ() {
        return this.ˎ == 2;
    }

    public void ˋ() {
        if (this.ॱ != null) {
            ॱ(0);
        }
    }

    public long ʼ() {
        return this.ॱ != null ? this.ॱ.ˋ() : -9223372036854775807L;
    }

    public long ʽ() {
        return this.ॱ != null ? this.ॱ.ॱ() : -1;
    }

    private void ॱ(int i) {
        this.ˎ = i;
        switch (i) {
            case 0:
                this.ˏ = 0;
                this.ʻ = -1;
                this.ˋ = System.nanoTime() / 1000;
                this.ˊ = 5000;
                return;
            case 1:
                this.ˊ = 5000;
                return;
            case 2:
            case 3:
                this.ˊ = 10000000;
                return;
            case 4:
                this.ˊ = 500000;
                return;
            default:
                throw new IllegalStateException();
        }
    }
}
